<template>
  <!-- 写评论的弹出层 -->
  <div class="comment-post">
    <van-field
      class="post-field"
      v-model.trim="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入留言"
      show-word-limit
    />
    <van-button @click="addPing" :disabled="!message" class="post-btn"
      >发布</van-button
    >
  </div>
</template>

<script>
import bus from "@/utils/eventBus.js";
import { addPing } from "@/api/coment.js";
export default {
  name: "CommentPost",
  components: {},
  props: {
    artId: {
      type: [String, Number],
      required: true,
    },
  },
  data() {
    return {
      message: "",
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    //   发布评论
    async addPing() {
      // 加载
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });
      try {
        const { data: res } = await addPing({
          target: this.artId,
          content: this.message,
        });
        this.message = "";
        this.$emit("isPingShow");
        bus.$emit("addlist", res);
        this.$toast.success("评论成功");
      } catch (error) {
        this.$toast("发布失败");
      }
    },
  },
};
</script>

<style scoped lang="less">
.comment-post {
  display: flex;
  align-items: center;
  padding: 32px 0 32px 32px;
  .post-field {
    background-color: #f5f7f9;
  }
  .post-btn {
    width: 150px;
    border: none;
    padding: 0;
    color: #6ba3d8;
    &::before {
      display: none;
    }
  }
}
</style>